package com.fare.taluo.application.impl.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.report.csair.CsairTaobaoApplication;
import com.fare.taluo.core.domain.analyse.report.CsairTaobaoEntity;
import com.fare.taluo.util.StringUtils;
import com.fare.taluo.vo.report.CsairTaobaoEntityVO;
@Transactional
@Scope("singleton")
@Service("csairTaobaoApplication")
public class CsairTaobaoApplicationImpl implements CsairTaobaoApplication{

	@Override
	public List<CsairTaobaoEntityVO> findByCondition(String fromCity,
			String toCity, String flightNo, String flightDate,String reportDate) {
		CsairTaobaoEntity entity = new CsairTaobaoEntity();
		List<CsairTaobaoEntity> entityList = entity.findByCondition(fromCity, toCity, flightNo, flightDate,reportDate);
		return this.convert2ListVO(entityList);
	}
	private List<CsairTaobaoEntityVO> convert2ListVO(List<CsairTaobaoEntity> entityList){
		List<CsairTaobaoEntityVO> voList = new ArrayList<CsairTaobaoEntityVO>();
		for (CsairTaobaoEntity entity : entityList) {
			CsairTaobaoEntityVO vo = new CsairTaobaoEntityVO();
			vo.setAgentName(entity.getAgentName());
			vo.setChannelKey(entity.getChannelKey());
			vo.setChannelPrice(entity.getChannelPrice());
			vo.setChannelName(entity.getChannelName());
			vo.setCreateTime(entity.getCreattime());
			vo.setFlightDate(entity.getFlightDate());
			vo.setFlightNo(entity.getFlightNo());
			vo.setFromCity(entity.getFromCity());
			vo.setFromCityName(entity.getFromCityName());
			vo.setHbaseKey(entity.getHbaseKey());
			vo.setPrice(entity.getPrice());
			vo.setReportDate(entity.getReportDate());
			vo.setSpread(entity.getSpread());
			vo.setSpreadAmount(entity.getSpreadAmount());
			vo.setToCity(entity.getToCity());
			vo.setToCityName(entity.getToCityName());
			voList.add(vo);
		}
		return voList;
	}
	@Override
	public Map<String, Map<String,CsairTaobaoEntityVO>> findByConditionToMap(
			String fromCity, String toCity, String flightNo, String flightDate,String reportDate) {
		Map<String, Map<String,CsairTaobaoEntityVO>> mapmap = new HashMap<String, Map<String,CsairTaobaoEntityVO>>();
		List<CsairTaobaoEntityVO> list = this.findByCondition(fromCity, toCity, flightNo, flightDate,reportDate);
		if(StringUtils.checkList(list)){
			String line = null;
			Map<String, CsairTaobaoEntityVO> map = new HashMap<String, CsairTaobaoEntityVO>();
			for (CsairTaobaoEntityVO csairTaobaoEntityVO : list) {
				line = csairTaobaoEntityVO.getFromCity()+"-"+csairTaobaoEntityVO.getToCity();
				map.put(csairTaobaoEntityVO.getChannelKey(), csairTaobaoEntityVO);
			}
			mapmap.put(line, map);
		}
		return mapmap;
	}
}
